package org.nanhill.osgi.example.biz.impl;

import java.util.Dictionary;
import java.util.Hashtable;

import org.nanhill.osgi.example.biz.LoginValidator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {

	private ServiceRegistration vam;

	private ServiceRegistration vbm;

	private BeanFactory beanFactory;

	public void start(BundleContext context) throws Exception {
		beanFactory = new BeanFactory();
		Dictionary<String, String> properties;
		LoginValidator va = beanFactory.getBean(ValidatorDefault.class,
				"validatorDefault");
		properties = new Hashtable<String, String>();
		properties.put("id", "default");
		vam = context.registerService(LoginValidator.class.getName(), va,
				properties);
		LoginValidator vb = beanFactory.getBean(ValidatorDB.class,
				"validatorDB");
		properties = new Hashtable<String, String>();
		properties.put("id", "db");
		vbm = context.registerService(LoginValidator.class.getName(), vb,
				properties);
	}

	public void stop(BundleContext context) throws Exception {
		vam.unregister();
		vbm.unregister();
		beanFactory = null;
	}

}
